package game.test;

import java.util.ArrayList;
import java.util.Random;
import chess.Board;

/**
 * This class will build tiles to test the eight queens games. Both methods are only meant for 
 * the testPlay method and the isMoveValid method
 * @author Caleb Chan
 * <pre>
 * - Created February 16, 2010
 * </pre>
 */
public class EightQueensTestSimulatorBuilder {
	
	
	public static final int SIMULATOR_DEFAULT_RANDOM = 100;
	
	private Random random;
	private Board board;
	private ArrayList<EightQueensSimulatorTileInfo> tileList;

	/**
	 * Creates a new simulator builder class for eight queens
	 * @param board Requires a board to generate tiles for testing
	 * <pre>
	 * Caleb Chan
	 * - Created February 16, 2010
	 * </pre>
	 */
	public EightQueensTestSimulatorBuilder(Board board){
		tileList = new ArrayList<EightQueensSimulatorTileInfo>();
		random = new Random();
		this.board = board;
	}
	/**
	 * This method will generate a random list of tile with specific instructions
	 * on how the tile is affected when a piece is placed there. This method should only be used 
	 * for testing the isValidMove method.
	 * @param numOfRandom The number of random tiles to be generated
	 * @return Returns a list of random tiles and info on affected status of the tile
	 * <pre>
	 * Caleb Chan
	 * - Created February 16, 2010
	 * </pre>
	 */
	public ArrayList<EightQueensSimulatorTileInfo> generateRandomTest(int numOfRandom){
		tileList.clear();
		int x;
		int y;
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(0, 0),EightQueensSimulatorTileInfo.PLACE_PIECE));
		for(int i = 0; i < numOfRandom; i++){
			
			do{
				x = random.nextInt(Board.BOARD_DIMENSION);
				y = random.nextInt(Board.BOARD_DIMENSION);
			}while((x == 0 && y == 0) || ((x != 0 && y != 0) && x != y));
			tileList.add(new EightQueensSimulatorTileInfo(board.getTile(x, y),EightQueensSimulatorTileInfo.INVALID_PIECE));
		}
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(2, 1),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(4, 2),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(4, 2),EightQueensSimulatorTileInfo.REMOVE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(4, 2),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(0, 0),EightQueensSimulatorTileInfo.REMOVE_PIECE));
		return tileList;
	}
	/**
	 * This method will return a list of the solution of an eight queens game. This method should
	 * only be used for testing the playGame method.
	 * @return Returns a list of the solution of eight queens
	 * <pre>
	 * Caleb Chan
	 * - Created February 16, 2010
	 * </pre>
	 */
	public ArrayList<EightQueensSimulatorTileInfo> generateSolution(){
		tileList.clear();
		
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(0, 6),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(1, 4),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(2, 2),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(3, 0),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(5, 7),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(4, 5),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(7, 3),EightQueensSimulatorTileInfo.PLACE_PIECE));
		tileList.add(new EightQueensSimulatorTileInfo(board.getTile(6, 1),EightQueensSimulatorTileInfo.PLACE_PIECE));
		
		return tileList;
	}
}
